import merge from 'deepmerge';
const baseOption = {};

export default async function getOption(dirName, chart) {
  const charDir = {
    FanXiang: 'FanXiang',
    KaiTong: 'KaiTong',
    XinYeWu: 'XinYeWu',
    ZongTi: 'ZongTi',
    TouSu: 'TouSu',
  }
  const optionModule = await import(`./${charDir[dirName]}/${chart}.js`);
  let option = optionModule.default;

  // 提示
  if (!window.isMobile && option.series && (option.series[0].type === 'bar' || option.series[0].type === 'line')) {
    option = merge(option, {
      toolbox: {
        show: true,
        feature: {
          dataZoom: {
            yAxisIndex: 'none',
            title: {
              zoom: '区域缩放',
              back: '区域缩放还原'
            }
          },
          magicType: {
            type: ['line', 'bar', 'stack'],
            title: {
              line: '切换为折线图',
              bar: '切换为柱状图',
              stack: '切换为堆叠模式',
              tiled: '切换为平铺'
            }
          },
          restore: {
            title: '还原'
          },
          saveAsImage: {
            title: '保存为图片'
          }
        }
      }
    });
  }

  return merge(baseOption, option);
}